#include <QApplication>
#include <QSettings>
#include <QSplashScreen>
#include "norwegianwoodstyle.h"
#include "mainwindow.h"

int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(ncat);

QApplication app(argc, argv);

app.setOrganizationName( QLatin1String("N-CAT") );
app.setOrganizationDomain( QLatin1String("n-cat.com") );
app.setApplicationName( QLatin1String("NCAT") );

QPixmap pixmap(":/binary/about.png");
QSplashScreen splash(pixmap);
splash.show();
app.processEvents();

QString app_path = app.applicationDirPath();
QStringList paths_list;
paths_list << app_path;
app.setLibraryPaths(paths_list);

QSettings settings( QSettings::IniFormat,
                    QSettings::UserScope,
                    app.organizationName(),
                    app.applicationName() );
settings.setFallbacksEnabled(false);
settings.beginGroup("GlobalSettings");
QString saved_style = settings.value("stylename").toString();
QString palette = settings.value("palette").toString();
QString language = settings.value("language").toString();
QString font_str = QLatin1String("");
font_str = settings.value("font").toString();
settings.endGroup();

QFont defaut_font = app.font();
QString defaut_font_str = defaut_font.toString();

    if ( true != font_str.isEmpty() )
    {
    QFont f;
    bool ok = false;
    ok = f.fromString(font_str);
        if ( true == ok )
        {
        app.setFont(f);
        }
    }

    if ( saved_style == QLatin1String("Cleanlooks" ) )
    {
    app.setStyle( new QCleanlooksStyle );
    }
    else if ( saved_style == QLatin1String("Windows" ) )
    {
    app.setStyle( new QWindowsStyle );    
    }
#ifdef Q_OS_WIN32
    else if ( saved_style == QLatin1String("WindowsXP" ) )
    {
    app.setStyle( new QWindowsXPStyle );    
    }
#endif
    else if ( saved_style == QLatin1String("NorwegianWood" ) )
    {
    app.setStyle( new NorwegianWoodStyle );    
    }
    else if ( saved_style == QLatin1String("Plastique" ) )
    {
    app.setStyle( new QPlastiqueStyle );    
    }
    else if ( saved_style == QLatin1String("CDE" ) )
    {
    app.setStyle( new QCDEStyle );
    }
    else if ( saved_style == QLatin1String("Motif" ) )
    {
    app.setStyle( new QMotifStyle );
    }
    else
    {
    }

    if ( palette == QLatin1String("TRUE") )
    {
        if ( app.style() != NULL )
        {
        app.setPalette( app.style()->standardPalette() );
        }
    }

MainWindow mainwindow(defaut_font_str);
   if ( language == QLatin1String("ru") )
   {
   mainwindow.check_ru();
   }
   else if ( language == QLatin1String("de") )
   {
   mainwindow.check_de();
   }
   /*   
   else if ( language == QLatin1String("zh_CN") )
   {
   mainwindow.check_zh_CN();
   }
   */
   else
   {
   mainwindow.check_en();
   }

mainwindow.show();
splash.finish(&mainwindow);
mainwindow.open_db();
return app.exec();
}

